﻿@model Himall.Model.ProductTypeInfo

@using Himall.Model
@using Himall.Web.Areas.Admin.Helper
@{
    ViewBag.Title = "Edit";

}



<script src="~/Areas/Admin/Scripts/ProductType.js"></script>
<style>
.hover_b{display:inline-block;padding:5px;border:1px solid #fff;}
.hover_b:hover{border:1px solid #e4e4e4;color:#f7604a;}
</style>
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>类型</strong>
        <li><a href="./Management">管理</a></li>
        <li class ="active"><a>新增</a></li>
        <em class="primary-btn">
            <span class="glyphicon glyphicon-question-sign"></span>
            <div class="primary">
                <h3>温馨提示：</h3>
                <span>*</span><p>类型是指某类具有相同描述特征的商品属性的集合，这个属性集合包括品牌、属性、规格。例如服装类型下的男装、女装都可以使用同一系品牌（NIKE、李宁）、属性（风格、材质）、规格（颜色、尺码）等</p>
            </div>
        </em>
    </ul>
    <form action="./SaveModel" method="post" class="form-horizontal" id="typeForm" role="form">
        <div class="form-group">
            <label for="" class="col-sm-2 control-label">类型名称：</label>
            <div class="col-sm-7">
                <input type="text" value="@Model.Name" name="Name" id="typeName" class="form-control input-sm" maxlength="40" />
                <span class="field-validation-error" id="typeNameTip"></span>
                <span style="display:none;" id="nameErrorMsg" class="help-default cor-red"><span>名称不能为空</span></span>
                <input type="hidden" name="Id" value="@Model.Id" id="Id"/>
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label">关联品牌：</label>
            <div class="col-sm-10 brand-letter" id="id_tab">
              
            </div>
            <div class="col-sm-10 brand-group">
                <div class="checkbox-group">
                </div>
                <div id="id_s" class="choose-brand">
                	<span>已选择：</span>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label for="" class="col-sm-2 control-label">属性：</label>
            <div class="col-sm-10">
                <table class="table table-bordered typeTable">
                    <thead>
                        <tr>
                            <th>属性名</th>
                            <th>属性值</th>
                            <th class="td-operate">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (Model.AttributeInfo == null || 0 == Model.AttributeInfo.Count())
                        {
                            <tr id="nonDataContainer">
                                <td style="text-align:center;" colspan="3">
                                    <h6>没有任何属性信息</h6>
                                </td>
                            </tr>
                        }
                        else
                        {
                            int index = 0;
                            foreach (var item in Model.AttributeInfo)
                            {
                                var attrName = "Attributes[" + index.ToString() + "].Name";
                                var attrValue = "Attributes[" + index.ToString() + "].Value";
                                var attrId = "Attributes[" + index.ToString() + "].Id";
                                var attrIsMulti = "Attributes[" + index.ToString() + "].IsMulti";
                                index++;
                                <tr class="currentRow">
                                    <td>
                                        <input type="hidden" value="@item.Id" name="@attrId" />
                                        <input class="attrIsMulti" name="@attrIsMulti" type="hidden" value="@item.IsMulti.ToString()" />
                                        <input class="attrName" name="@attrName" type="hidden" value="@item.Name" />
                                        <span class="spanAttrName">@item.Name</span>
                                    </td>
                                    <td>
                                        <input class="attrValue" name="@attrValue" type="hidden"
                                               value="@item.AttrValue" />
                                        <span class="spanAttrValue" style="max-width:500px;word-break:break-all;">@item.AttrValue</span>
                                    </td>
                                    <td class="td-operate"><span class="btn-a"><a class="attrEdit">编辑</a><a class="attrDelete">删除</a></span></td>
                                </tr>

                            }
                        }

                    </tbody>
                </table>
                <a class="add-atrr"><span class="glyphicon glyphicon-plus-sign"></span>新增一个属性</a>
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label">规格：</label>
            <div class="col-sm-10 type">
                <div class="type-list" id="divColor">
                    @Html.GenerateSpecification(Model, SpecificationType.Color)
                </div>
                <div class="type-list" id="divSize">
                    @Html.GenerateSpecification(Model, SpecificationType.Size)
                </div>
                <div class="type-list" id="divVersion">
                    @Html.GenerateSpecification(Model, SpecificationType.Version)
                </div>
                <p class="help-block">您可勾选该类型下会用到的规格，并为其设定默认值，商家可修改规格值名称（不会影响平台数据）。</p>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="button" onclick="subForm();" class="btn btn-primary" value="保 存" />
            </div>
        </div>
    </form>


</div>
<script>
    $(function () {
        $("#typeName").blur(function () {
            var name = $('#typeName').val();
            var reg = /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/;
            if (name.length > 12||!name)
            {
                $("#typeNameTip").text("请输入1至12个字符！");
                $('#typeName').css({ border: '1px solid #f60' });
                return false;
            }
            if (reg.test(name) == false) {
                $("#typeNameTip").text("品牌名称必须是中文，字母，数字和下划线！");
                $('#typeName').css({ border: '1px solid #f60' });
                return false;
            }
            else {
                $("#typeNameTip").text("");
                $('#typeName').css({ border: '1px solid #ccc' });
            }
        })
    })
</script>